﻿@model Dictionary<string, bool>

<div class="dashboard" id="dashboard">
    <div class="leftSide">
        <div class="executionChart">
            <img src="/Home/CreateChart" alt="" />
        </div>
        <div id="statistics" class="statistics">
        @if (ViewBag.PDate != null)
        {
            <div class="previosExecutionsCombo">
                @using (Ajax.BeginForm("Index", null, new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "statistics", InsertionMode = InsertionMode.Replace }, new { id = "ExecutionHistory" }))
                {
                    <text>Execution history: </text>
                    <select id="executionId" name="executionId" onchange="document.forms['ExecutionHistory'].submit();">
                        @foreach (var item in (List<SelectListItem>)ViewBag.ExecutionList)
                        {
                            if (item.Selected)
                            {
                                <option value="@item.Value" selected = "selected">@item.Text</option>
                            }
                            else
                            {
                                <option value="@item.Value">@item.Text</option>
                            }
                        }
                    </select>
                }
            </div>
            <p>Last run at <span style="font-size: 9px;">(excluding currently running)</span>: @ViewBag.PDate</p>
            <p>Status: 
                @switch ((string) ViewBag.PStatus)
                {
                    case "Pass":
                        <span style="color: green">Pass</span>
                        break;
                    case "Fail":
                        <span style="color: red">Fail</span>
                        break;
                    case "Warning":
                        <span style="color: goldenrod">Warning</span>
                        break;
                }
            </p>
            <p>Details:</p>
            <p style="padding-left: 50px;">Group: @ViewBag.PGroup</p>
            <p style="padding-left: 50px;">Runtimes: @ViewBag.PRuntimes</p>
            <p style="text-align: center">@Html.ActionLink("Click here for detailed results", "Index", "Results", new {id = ViewBag.PId}, new {})</p>
        }    
        </div>
    </div>
    <div class="rightSide">
        <div class="groups">
            @using (Ajax.BeginForm("Index", null, new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "dashboard", InsertionMode = InsertionMode.Replace }, new { id = "Group" }))
            {
                <text>Group: </text>
                <select id="Group" name="Group" onchange="document.forms['Group'].submit();">
                    @foreach (var item in (List<SelectListItem>)ViewBag.Group)
                    {
                        if (item.Selected)
                        {
                            <option value="@item.Value" selected = "selected">@item.Text</option>
                        }
                        else
                        {
                            <option value="@item.Value">@item.Text</option>
                        }
                    }
                </select>
            }
        </div>
        <div class="executionStatus">
            <div id="currentState">Current state: 
                @if (ViewBag.CurrentState == "Idle")
                {
                    @ViewBag.CurrentState
                }
                else
                {
                    <a href="#" class="cStateTooltip" rel="/Home/GetCurrentState">@ViewBag.CurrentState</a>
                    <a href="/Home/StopExecution?g=@ViewBag.SelectedGroup"><img width="20" height="20" src="../../Images/stop.png" alt="Stop execution"></a>
                }
            </div>
            <div id="remainingTime">
                @if (ViewBag.CurrentState == "Idle")
                {
                    <span>&nbsp;</span>
                }
                else
                {
                    <span>Estimated remaining time: <span id="countdown"></span></span>
                    <script type="text/javascript">
                        $('#countdown').countdown({ until: '@ViewBag.RemainingTime', compact: true, format: 'HMS' });
                    </script>
                }
            </div>
        </div>
        @if (ViewBag.CurrentState != "Idle" && Model != null && Model.Count > 0)
        {
            <div class="profilesGridHolder">
                <div class="profilesGrid">
                    <div class="profilesGridTitle">
                        <div class="profilesGridColumnLeft">Profiles Completed</div>
                        <div class="profilesGridColumnRight">Profiles Remaining</div>
                    </div>
                    <div class="profilesGridRow">
                        <div class="profilesGridColumnLeft">
                            @foreach (var profile in Model.Where(p => p.Value))
                            {
                                <p>@profile.Key</p>
                            }
                        </div>
                        <div class="profilesGridColumnRight">
                            @foreach (var profile in Model.Where(p => !p.Value))
                            {
                                <p>@profile.Key</p>
                            }
                        </div>
                    </div>
                </div>
            </div>
        }
    </div>
</div>